<template>
  <common-page title="详情">
    <el-button slot="header" @click="back">返回</el-button>
    <div slot="content" class="notice-wrap">
      <detail-content :detail="detail" v-loading="loading"></detail-content>
    </div>
  </common-page>
</template>

<script>
import DetailContent from "../notice/components/detailContent.vue";
import { fetchInfoDetail } from "@/api/system/publicNotice";
export default {
  components: {
    DetailContent,
  },
  data() {
    return {
      loading: false,
      contentShow: false,
      detail: {},
    };
  },

  mounted() {
    this.getDetailInfo(this.$route.query.noticeId);
    
    this.$bus.$on("LASTEST_NOTICE_CLICK", (noticeId) => {
      this.getDetailInfo(noticeId);
    });
  },

  beforeDestroy() {
    this.$bus.$off("LASTEST_NOTICE_CLICK");
  },

  methods: {
    getDetailInfo(noticeId) {
      this.loading = true;
      if (noticeId) {
        fetchInfoDetail({ noticeId: noticeId })
          .then((res) => {
            if (res && res.code === 200) {
              if (res.data) {
                this.detail = res.data;
                this.contentShow = true;
                //获取通知个数
                // this.$bus.$emit("messageList");
              } else {
                this.detail = {};
                this.$GlobalErrorConfirm("警告", "该公告已被删除");
                // this.$bus.$emit("messageListChange");
                this.$router.push("/");
              }
            }
          })
          .finally(() => {
            this.loading = false;
          });
      }
    },
    back() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang="scss" scoped>
.notice-wrap {
  width: 65%;
  margin: auto;
  margin-top: 30px;
  height: calc(100% - 70px);
  box-shadow: 0 1px 8px 0 rgb(0 0 0 / 5%);
  border: 1px solid #eee;
  border-radius: 4px;
}
</style>